<template>
  <el-container class="home-container">
    <el-aside :width="menuCollapse?'64px':'200px'">
      <div class="logoClass">{{systemName}}</div>
      <el-menu
        background-color="#D3DCE6"
        text-color="#171818"
        active-text-color="#409EFF"
        unique-opened
        :collapse-transition="false"
        :collapse="menuCollapse"
        router
        :default-active="activePath"
      >
        <el-submenu :index="item.id+''" v-for="item in list" :key="item.id">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>{{ item.menuName }}</span>
          </template>
          <el-menu-item :index="subItem.path" v-for="subItem in item.children"
                        :key="subItem.id" @click="saveNavStat(subItem.path)">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ subItem.menuName }}</span>
            </template>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div>
          <div class="toggle-button" @click="toggleButton">
            <i :class="toggleClass"></i>
          </div>
        </div>
        <el-button type="text">mouse</el-button>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

export default {
  name: 'Home',
  data () {
    return {
      systemName: '元宇宙平台',
      toggleClass: 'el-icon-s-fold',
      activePath: '',
      menuCollapse: false,
      list: [
        {
          id: 1,
          menuName: '商品管理',
          path: null,
          order: 1,
          children: [
            {
              id: 11,
              menuName: '商品列表',
              path: '/goods',
              order: 11,
              children: []
            },
            {
              id: 12,
              menuName: '品牌列表',
              path: '/brands',
              order: 12,
              children: []
            }
          ]
        },
        {
          id: 2,
          menuName: '权限管理',
          path: null,
          order: 2,
          children: [
            {
              id: 22,
              menuName: '用户列表',
              path: null,
              order: 22,
              children: []
            },
            {
              id: 23,
              menuName: '字典列表',
              path: null,
              order: 23,
              children: []
            }
          ]
        }
      ]
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    toggleButton () {
      this.menuCollapse = !this.menuCollapse
      this.toggleClass = this.menuCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
      this.systemName = this.menuCollapse ? '元' : '元宇宙平台'
    },
    saveNavStat (path) {
      window.sessionStorage.setItem('activePath', path)
      this.activePath = path
    }
  }
}
</script>
<style lang='less' scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #72a7e8;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  font-size: 20px;
  color: #E9EEF3;

  > div {
    display: flex;
    align-items: center;

    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #D3DCE6;

  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #E9EEF3;

}

.toggle-button {
  height: 60px;
  width: 25px;
  color: #E9EEF3;
  font-size: 26px;
  line-height: 50px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.logoClass {
  height: 60px;
  font-size: 20px;
  line-height: 60px;
  text-align: center;
}
</style>
